package com.stylefeng.guns.core.util.excel.demo.export;

import com.stylefeng.guns.core.util.excel.ExportExcelXlsComponent;
import com.stylefeng.guns.core.util.excel.demo.DemoExcelBo;
import org.apache.commons.collections.CollectionUtils;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;

import java.util.ArrayList;
import java.util.List;

/**
 * 导入案例仅供参考
 * @author carloszhang
 *
 */
public class DemoExcelExport extends ExportExcelXlsComponent<DemoExcelBo> {

    @Override
    protected void buildExcelDatas(HSSFSheet sheet, List<DemoExcelBo> datas) {

        if (CollectionUtils.isEmpty(datas)) return;
        HSSFRow row = null;
        int rowIndex = 1;
        for (DemoExcelBo data : datas) {
            row = sheet.createRow(rowIndex);
            createCell(row, 0).setCellValue(trimData(data.getId()));
            createCell(row, 1).setCellValue(trimData(data.getName()));
            rowIndex++;
        }
    }

    @Override
    protected List<String> buildHeader() {
        List<String> header = new ArrayList<String>();
        header.add("序号");
        header.add("姓名");
        return header;
    }
}
